import request from '@/utils/request'
import type { PermissionResponseData, MenuParams } from './type'

enum API {
  //获取全部菜单与按钮的数据
  ALLPERMISSION_URL = '/admin/acl/permission',
  //新增菜单
  ADDMENU_URL = '/admin/acl/permission/save/',
  //更新菜单
  UPDATEMENU_URL = '/admin/acl/permission/update/',
  //删除已有的菜单
  DELETEMENU_URL = '/admin/acl/permission/remove/'
}

//获取菜单
export const reqAllPermission = () =>
  request.get<any, PermissionResponseData>(API.ALLPERMISSION_URL)

//新增或更新菜单
export const reqAddRoUpdateMenu = (data: MenuParams) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATEMENU_URL, data)
  } else {
    return request.post<any, any>(API.ADDMENU_URL, data)
  }
}

//删除已有的菜单
export const reqRemoveMenu = (id: number) => request.delete<any, any>(API.DELETEMENU_URL + id)
